// TODO 公共
import {ImagePreview} from "vant";

/**
 * @description 通用 预览图片
 * @type {{components: {[p: string]: VanComponent}, methods: {showPreview(*): void}}}
 */
const Preview = {
  components: {
    [ImagePreview.Component.name]: ImagePreview.Component,
  },
  inject: ['_instance_before'],
  computed: {
    instance_before() {
      return this._instance_before();
    }
  },
  methods: {
    /**
     * @description 显示预览图调用
     * @param oneAndPaths {array | string}  网络地址 or 多个
     * @param index {number} 指向索引
     */
    showPreview(oneAndPaths, index = 0) {
      const arr = []
      if(typeof oneAndPaths === "string" || Object.prototype.toString.call(oneAndPaths) === '[object String]') {
        arr.push(oneAndPaths)
      } else if(oneAndPaths instanceof Array) {
        arr.push(...oneAndPaths)
      }
      this.instance_before.preview = ImagePreview({
        images: arr,
        loop: false,
        showIndex:true, //是否显示页码
        startPosition: index,
        closeable: false,
      })
    },
  }
}

export {
   Preview,
}

